package cn.com.dcsgo.exception;

import cn.com.dcsgo.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.Serializable;

/**
 * 全局异常处理
 *
 * @author Dcsgo
 * @since 2025/3/17 16:34
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Throwable.class)
    public Result<Serializable> error(Throwable throwable) {
        log.error("GlobalExceptionHandler.error：{}", throwable.getClass().getName() + ": " + throwable.getMessage());
        return Result.fail(null);
    }

    @ExceptionHandler(UuPreferredException.class)
    public Result<Serializable> uuPreferredException(UuPreferredException e) {
        log.error("GlobalExceptionHandler.uuPreferredException：{}", e.getMessage());
        return Result.build(null, e.getCode(), e.getMessage());
    }
}
